import {get, post, ID, STATION, SERVER} from "./common";
import {computed, reactive} from "vue";
import store from "../store";


/**
 * 根据设备id查找病人信息
 */
export function find(deviceId) {
    const patientData=computed(() => store.state.patientData)
    for (let patient of patientData.value) {
        if (patient.deviceId === parseInt(deviceId)) {
            return patient;
        }
    }
    return null;
}


/**
 * 根据queNumber查找病人信息
 */
export function findByQno(qno) {
    const patientData=computed(() => store.state.patientData)
    for (let patient of patientData.value) {
        if (patient.queNumber === qno) {
            return patient;
        }
    }
    return null;
}


/**
 * 告诉后端有病床通话发起/结束
 * id: 病床号（排队号）
 * ask: 呼叫（true）/挂断（false）
 */
export function signal(id, ask, type) {
    const params = reactive({
        ask: false,
        id: id,
        type: type
    })
    return get('/bed/signal', params);
}

export function getCallRecord(form) {
    return post('/station/callRecord/get', form);
}

export function callRecord(params) {
    // const params = reactive({
    //     callId: callId,
    //     calledName: calledName,//被呼叫的人的姓名（护士站ID或者患者姓名）
    //     calledId: calledId,
    //     startTime: startTimeStamp,
    //     endTime: endTimeStamp,
    // })
    return post('/bed/callRecord', params);
}

export function online(id) {
    return get('http://' + SERVER.call.ip + ':' + SERVER.call.port + '/call/isOnline?deviceId=' + id);
}
